package com.ctsi.filestore.app.config;

import com.ctsi.commons.util.UtilValidate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class UploadFilePathConfig extends WebMvcConfigurerAdapter {

    @Value("${file-store.upload.dir}")
    private String finalDirPath;

    @Value("${file-store.static-access-path}")
    private String staticAccessPath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        if (UtilValidate.isNotEmpty(finalDirPath)) {
            registry.addResourceHandler(staticAccessPath).
                    addResourceLocations("file:" + finalDirPath);
//                    .addResourceLocations("classpath*:/META-INF/static/");
        }
    }
}
